#ifndef __EV_GNSS_SN_DATA_H__
#define __EV_GNSS_SN_DATA_H__


#include<stdint.h>
#include<string>
#include<vector>
#include"EvGnssSNDataSub.hpp"
#include"rapidjson/document.h"


namespace SC_SUN
{

struct EvGnssSNData
{

//////单星信息汇总//////
/*
长度：5位
范围：1- SAT_NUM
格式：SAT+XXXXX
【SAT0000*】
【SAT000**】
【SAT00***】
【SAT0****】
【SAT*****】
*/
std::string SAT_SN;                                 ///< 卫星序号
double GNSS_TT;                                     ///< GNSS仿真时长
double GNSS_STP;                                    ///< GNSS仿真步长
uint16_t GNSS_NUM;                                  ///< GNSS切片数量

//////存储地址//////                                 
std::string PATH_SAT_SN;                            ///< 单星文件夹地址和文件夹名

//////GNSS切片信息及存储地址//////
std::string GNSS_SN;                                ///< GNSS切片序号
double GNSS_ST;                                     ///< GNSS切片仿真时
uint16_t GNSS_WD;                                   ///< GNSS卫星可见数量
std::string PATH_GNSS_SN;                           ///< GNSS切片文件地址和文件名


EvGnssSNDataSub GNSS_SN_DATA;


//用于将必要的数据转换成json字符串
void ObjToJsonObject(rapidjson::Document& doc)
{
    using namespace rapidjson;

    doc.AddMember(Value("SAT_SN", doc.GetAllocator()), Value(SAT_SN.data(), doc.GetAllocator()), doc.GetAllocator());
    doc.AddMember(Value("GNSS_TT", doc.GetAllocator()), Value(GNSS_TT), doc.GetAllocator());
    doc.AddMember(Value("GNSS_STP", doc.GetAllocator()), Value(GNSS_STP), doc.GetAllocator());
    doc.AddMember(Value("GNSS_NUM", doc.GetAllocator()), Value((uint32_t)GNSS_NUM), doc.GetAllocator());
    doc.AddMember(Value("GNSS_path", doc.GetAllocator()), Value(PATH_SAT_SN.data(), doc.GetAllocator()), doc.GetAllocator());

    doc.AddMember(Value("GNSS_SN", doc.GetAllocator()), Value(GNSS_SN.data(), doc.GetAllocator()), doc.GetAllocator());
    doc.AddMember(Value("GNSS_ST", doc.GetAllocator()), Value(GNSS_ST), doc.GetAllocator());
    doc.AddMember(Value("GNSS_WD", doc.GetAllocator()), Value((uint32_t)GNSS_WD), doc.GetAllocator());
    doc.AddMember(Value("PATH_GNSS_SN", doc.GetAllocator()), Value(PATH_GNSS_SN.data(), doc.GetAllocator()), doc.GetAllocator());

    doc.AddMember(Value("GNSS_SAT_SN", doc.GetAllocator()), Value(GNSS_SN_DATA.GNSS_SAT_SN.data(), doc.GetAllocator()), doc.GetAllocator());
    Value value(kArrayType);
    value.PushBack(GNSS_SN_DATA.GNSS_SAT_POS[0], doc.GetAllocator());
    value.PushBack(GNSS_SN_DATA.GNSS_SAT_POS[1], doc.GetAllocator());
    value.PushBack(GNSS_SN_DATA.GNSS_SAT_POS[2], doc.GetAllocator());
    doc.AddMember(Value("GNSS_SAT_SN", doc.GetAllocator()), value, doc.GetAllocator());

    doc.AddMember(Value("GNSS_SAT_PR", doc.GetAllocator()), Value(GNSS_SN_DATA.GNSS_SAT_PR), doc.GetAllocator());
    doc.AddMember(Value("GNSS_SAT_RC", doc.GetAllocator()), Value(GNSS_SN_DATA.GNSS_SAT_RC.data(), doc.GetAllocator()), doc.GetAllocator());
    doc.AddMember(Value("GNSS_SAT_NM", doc.GetAllocator()), Value(GNSS_SN_DATA.GNSS_SAT_NM.data(), doc.GetAllocator()), doc.GetAllocator());
}


static EvGnssSNData JsonToObj(const rapidjson::Document& doc)
{
    using namespace rapidjson;

    auto obj = doc.GetObj();
    EvGnssSNData ret;

    ret.SAT_SN = obj["SAT_SN"].GetString();
    ret.GNSS_TT = obj["GNSS_TT"].GetDouble();
    ret.GNSS_STP = obj["GNSS_STP"].GetDouble();
    ret.GNSS_NUM = obj["GNSS_NUM"].GetUint();
    ret.PATH_SAT_SN = obj["GNSS_path"].GetString();

    ret.GNSS_SN = obj["GNSS_SN"].GetString();
    ret.GNSS_ST = obj["GNSS_ST"].GetDouble();
    ret.GNSS_WD = obj["GNSS_WD"].GetUint();
    ret.PATH_GNSS_SN = obj["PATH_GNSS_SN"].GetString();

    ret.GNSS_SN_DATA.SAT_SN = ret.SAT_SN;
    ret.GNSS_SN_DATA.GNSS_ST = ret.GNSS_ST;
    ret.GNSS_SN_DATA.GNSS_WD = ret.GNSS_WD;
    ret.GNSS_SN_DATA.GNSS_SAT_SN = obj["GNSS_SAT_SN"].GetString();

    ret.GNSS_SN_DATA.GNSS_SAT_POS[0] = obj["GNSS_SAT_POS"].GetArray()[0].GetDouble();
    ret.GNSS_SN_DATA.GNSS_SAT_POS[1] = obj["GNSS_SAT_POS"].GetArray()[1].GetDouble();
    ret.GNSS_SN_DATA.GNSS_SAT_POS[2] = obj["GNSS_SAT_POS"].GetArray()[2].GetDouble();

    ret.GNSS_SN_DATA.GNSS_SAT_PR = doc["GNSS_SAT_PR"].GetDouble();
    ret.GNSS_SN_DATA.GNSS_SAT_RC = obj["GNSS_SAT_RC"].GetString();
    ret.GNSS_SN_DATA.GNSS_SAT_NM = obj["GNSS_SAT_NM"].GetString();

    return ret;
}
};

}

#endif